#ifndef _RAM_HANDLE_MANAGE_H_
#define _RAM_HANDLE_MANAGE_H_

#include <memory>
#include <functional>
#include <string>
#include <thread>
#include <mutex>
#include <map>
#include "Event.h"
#include "common.h"
#include "MacType.h"

class RawIoInterface;
class TaskTimer;

class DataForward : public Event
{
public:

    explicit DataForward(std::string srcmac, RawType type);
    virtual ~DataForward();

    int init();
    int shutdown();

    int VSubscribe(Type type, std::function<void(MacType, DataCache)> func);
    int VUnsubscribe(Type type);

    int SendDataByAddr(MacType addr, Type type, DataCache data, int timeout);

private:

    int ProcessPackage(DataCache& dstData, DataCache& srcData);

    virtual void CycleTask();

    std::map<Type, std::function<void(MacType, DataCache)>>  m_func;
    
    MacType                 m_src_mac;
    std::string             m_macstr;

    std::mutex              m_mutex;

    RawType                 m_type_io;
    RawIoInterface*         m_raw_io;

    TaskTimer*              m_time_task;
};
typedef std::shared_ptr<DataForward> DataForwardPtr;

#endif
